<!DOCTYPE html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <script src="./js/vue.js"></script>
    <style>
        body {
            background-color: aliceblue;
        }

        #app {
            width: 50%;
            margin: 20px auto;
            background-color: #fff;
            border: 5px solid blueviolet;
            border-radius: 1em;
            box-shadow: 3px 3px 3px rgba(0, 0, 0, 0.5);

        }

        h3 {
            text-align: center;
        }

        .title {
            display: flex;
            justify-content: space-between;
            align-items: center;
            /* text-align: center; */
            border: 1px solid #ccc;
        }

        .title h4 {
            line-height: 2;
            margin: 0;
        }
    </style>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="(items,index) in arr" :key='index'>{{items}}<button @click="fn2(index)">删除</button></li>
        </ul>
        <button @click='fn()'>生成</button>


    </div>

    <script>
        var app = new Vue({
            el: '#app',
            data() {
                return {
                    arr: [1, 2, 3]
                }
            },
            methods: {
                fn() {
                    //生成随机数
                    let mun = Math.floor(Math.random() * 20)
                    //添加到arr
                    this.arr.push(mun)
                },
                fn2(index) {
                    //通过传参拿到数组的下标,删除指定下标的元素
                    this.arr.splice(index, 1)
                }
            }
        })

    </script>
</body>
</body>

</html>